package MyApp.View.well
{
	import MyApp.Context;
	import MyApp.Model.LoginUser;
	import MyApp.Model.WellPrdRecord;
	import MyApp.Model.proxy.WellProxy;
	import MyApp.MyAppFacade;
	
	import components.well.AddPrdRecord;
	import components.well.WellContext;
	import components.well.WellWindow;
	
	import flash.events.MouseEvent;
	
	import mx.events.CloseEvent;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import util.Constants;
	import util.GDUtil;
	
	public class AddPrdRecordMediator extends Mediator
	{
		public static const NAME:String=GDUtil.getUID();
		public function AddPrdRecordMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			view.addEventListener(CloseEvent.CLOSE,doClose);
			view.addEventListener(AddPrdRecord.DO_SAVE,doSave);
		}
		private function get view():AddPrdRecord{
			return viewComponent as AddPrdRecord;
		}
		private function doSave(e:MouseEvent):void{
			view.currentState="loading";
			var lu:LoginUser=Context.instance.getProperty(Constants.LOGINUSER_KEY) as LoginUser;
			var prd:WellPrdRecord=new WellPrdRecord();
			prd.date=new Date(WellContext.queryDate.fullYear,WellContext.queryDate.month,view.day.selectedItem.value);
			prd.owner=lu.name;
			prd.wellTeamId=WellContext.wellGroup.wellGroupId;
			prd.wellTeamName=WellContext.wellGroup.wellGroupName;
			prd.waterIn=Number(view.waterIn.text);
			prd.oilIn=Number(view.oilIn.text);
			prd.preduction=Number(view.preduction.text);
			prd.na2so4PerL=Number(view.na2so4PerL.text);
			prd.naclPerL=Number(view.naclPerL.text);
			prd.naclWaterPerL=Number(view.naclWaterPerL.text);
			prd.na2so4Total=Number(view.na2so4Total.text);
			prd.naclTotal=Number(view.naclTotal.text);
			prd.naclTotalNoWater=Number(view.naclTotalNoWater.text);
			prd.pipePressureIn=Number(view.pipePressureIn.text);
			prd.pressureBack=Number(view.pressureBack.text);
			prd.waterTemperature=Number(view.waterTemperature.text);
			prd.na2so4Temperature=Number(view.na2so4Temperature.text);
			prd.operator=view.operator.text;
			prd.auditer=view.auditer.text;
			prd.produceMethod=view.produceMethod.text;
			prd.remark=view.remark.text;
			this.sendNotification(WellWindow.DO_ADD_PRDRECORD,prd);
		}
		private function doClose(e:CloseEvent):void{
			MyAppFacade.closePopUpWindow(view,NAME);
		}
		override public function listNotificationInterests():Array{
			return [WellProxy.ADD_PRD_RECORD_OK];
		}
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case WellProxy.ADD_PRD_RECORD_OK:
					MyAppFacade.closePopUpWindow(view,NAME);
					break;
			}
		}
	}
}